#include "accept.h"
#include "arrow/log.h"
#include "../session/session.h"

namespace ArrowWebCodeView
{

CAccept::CAccept(asio::io_context& ioContext, const tcp::endpoint& tcpEndPoint)
:m_IoContext(ioContext), m_Acceptor(ioContext, tcpEndPoint), m_Socket(ioContext)
{
    DoAccept();
}

CAccept::~CAccept()
{
}

void CAccept::DoAccept()
{
    m_Acceptor.async_accept(m_Socket, [this](boost::system::error_code ec)
        {
            if (!ec)
            {
                std::string strTmp = m_Socket.remote_endpoint().address().to_string() + std::string(":") +
                                     std::to_string(m_Socket.remote_endpoint().port());
                std::make_shared<CSession>(m_IoContext, std::move(m_Socket), strTmp)->Start();
            }
            DoAccept();
        }
    );
}

}